home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / assembly / trashed1.lzh / trashEd1.0 / trashEdMode.FPL < prev    next >
Text File  |  1995-10-06  |  6KB  |  252 lines

  1. // $Id: TrashMOneMode.FPL 1.8 1995/09/03 12:49:32 jskov Exp jskov $
  2. // $VER: TrashMOneMode.FPL 1.0 (20.07.95) © Jesper Skov
  3.  
  4. // General note:
  5. // Using the FrexxEd filehandler is too slow! Therefore a temp file is used instead
  6.  
  7.  
  8. // Trash'M-One states:
  9. // 'a' assembling (assemble % in [1-3])
  10. // 'f' assembling failed (waiting)
  11. // 'o' assembling OK
  12. // 'u' user has control
  13. // 'w' waiting for external command
  14.  
  15. int trashBuffer=0;                            // Id of the buffer 
  16.  
  17. export string status;
  18.  
  19. string tempName;
  20. int line;
  21. int bytepos;
  22. int validChanges;
  23.  
  24. int timerID=0;
  25.  
  26. int errorBufferID=0;
  27. int errorsValid=0;
  28.  
  29. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» assembleBuffer() ««
  30. // Pass the buffer to trash'm-One for assembly
  31. //»»»»»»»»»»»»»»»»»»»»»»»»»»
  32. void export assembleBuffer(int assemble)
  33. {
  34.   if (ReadInfo("protectionbits")&4){
  35.     Request("Sorry, buffer is write protected!\nDe-protect and try again!","TrashInfo...","OK");
  36.     return;
  37.   } else {
  38.     if (errorBufferID)
  39.       ExecuteString("Kill("+itoa(errorBufferID)+");");
  40.     errorBufferID = 0;
  41.  
  42.     getStatus();
  43.  
  44.     if (status[0]!='f' && status[0]!='w'){
  45.       if(Request("Trash'm-One not ready for command!\nShould it be popped to front?","TrashInfo...","Yes|No"))
  46.         popTrash();
  47.       return;
  48.     } else {
  49.  
  50.       validChanges = ReadInfo("changes");
  51.  
  52.       tempName = joinstr("T:",ReadInfo("file_name"));
  53.  
  54.       line = ReadInfo("line");
  55.       bytepos = ReadInfo("byte_position");
  56.  
  57.       trashBuffer = GetBufferID();
  58.       Save(tempName);
  59.       SetInfo(-1,"changes",validChanges);        // Remember the changed flag
  60.  
  61.       if (assemble){
  62.         System(joinstr("activateTrash \"",tempName,"\""));
  63.         popTrash();
  64.       } else {
  65.         System(joinstr("activateTrash \"",tempName,"\" ASSEMBLE"));
  66.         addInfo();
  67.       }
  68.     }
  69.   }
  70. }
  71.  
  72. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» activateSource() ««
  73. // Called from trash'm-One to re-load the source in FrexxEd
  74. //»»»»»»»»»»»»»»»»»»»»»»»»»»
  75. void export activateSource()
  76. {
  77.   if (trashBuffer){
  78.     string oldName;
  79.  
  80.     removeInfo();
  81.  
  82.     if (validChanges!=ReadInfo("changes"))    // If buffer has changed make sure reload is wanted
  83.       if (Request("Trash'm-One requests a reload\nbut the buffer has been changed!?!","Trash request...", "Ignore request|Reload")){
  84.         ReturnStatus(joinstr("Reload of \"",tempName,"\" canceled!"));
  85.         exit;
  86.       }
  87.  
  88.     CurrentBuffer(trashBuffer);
  89.     oldName = ReadInfo("full_file_name");
  90.     Clean(joinstr("Load(\"",tempName,"\");"));
  91.     Rename(oldName);
  92.     SetInfo(-1,"changes",validChanges);        // Remember the changed flag
  93.  
  94.     getStatus();
  95.     if (status[0]=='f'){
  96.       nextError();
  97.     } else {
  98.       GotoLine(line, bytepos);
  99. //      CenterView();
  100.     }
  101.  
  102.     Activate();
  103.     trashBuffer = 0;
  104.   }
  105. }
  106.  
  107. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» addInfo() ««
  108. void addInfo()
  109. {
  110.   timerID = TimerAdd(1,"setPercentage();",0,100);
  111. }
  112.  
  113. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» removeInfo() ««
  114. void removeInfo()
  115. {
  116.   TimerDelete(timerID);
  117. }
  118.  
  119. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» setPercentage() ««
  120. export void setPercentage()
  121. {
  122.   string progressBar = "p ..........";
  123.   int i, value;
  124.  
  125.   getStatus();
  126.   if (status[0]=='a'){
  127.  
  128.     progressBar[0]=status[1]+1;                // set pass
  129.  
  130.     value = atoi(substr(status,1,-1));
  131.     if (value>100)
  132.       value-=100;
  133.  
  134.     for (i=0;i<(value/10);i++)
  135.       progressBar[i+2]='»';
  136.  
  137.     SetInfo(-1,"trashProgress",progressBar);
  138.     RedrawScreen();
  139.  
  140.   } else {
  141.     SetInfo(-1,"trashProgress", ". ..........");
  142.     RedrawScreen();
  143.  
  144.     removeInfo();
  145.  
  146.     if (status[0]=='o')
  147.       popTrash();
  148.   }
  149. }
  150.  
  151. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» getStatus() ««
  152. void getStatus()
  153. {
  154.   System("activateTrash address");
  155.   System("getTrashValues");
  156.   status = GetEnv("trashStat");
  157.   if (!strlen(status))
  158.     status = "z000";                        // sleeping!?!?
  159.  
  160. }
  161.  
  162. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» popTrash() ««
  163. void popTrash()
  164. {
  165.   System("trashToFront");
  166. }
  167.  
  168.  
  169. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» nextError() ««
  170. export void nextError()
  171. {
  172.   int parentBuffer;
  173.  
  174.   if (!errorBufferID){
  175.     if (!Check("T:trashLog")){
  176.       Request("Log from Trash'm-One not found!?!","TrashInfo...","Huh?");
  177.       return;
  178.     } else {
  179.       errorBufferID = New();
  180.       parentBuffer = CurrentBuffer(errorBufferID);
  181.       Load("T:trashLog");
  182.       errorsValid = 1;
  183.       CurrentBuffer(parentBuffer);
  184.     }
  185.   }
  186.  
  187.   // We have an error buffer!
  188.  
  189.   if (!errorsValid){
  190.     Request("Log not valid!","TrashInfo...","OK!");
  191.     return;
  192.   } else {
  193.     int retry = 1;
  194.  
  195.     parentBuffer = CurrentBuffer(errorBufferID);
  196.     
  197.     while(retry){
  198.       retry = 0;
  199.  
  200.       if (Search("** ","=f+")){
  201.         if(!Request("No more errors found!","TrashInfo...","OK|Wrap")){
  202.           retry = 1;
  203.           GotoLine(1);
  204.         }
  205.         CurrentBuffer(parentBuffer);
  206.       } else {
  207.         string errorMsg = substr(GetLine(),ReadInfo("byte_position")+3,ReadInfo("line_length")-ReadInfo("byte_position")-5);
  208.  
  209.         CursorDown();
  210.  
  211.         // Check "Code moved" etc
  212.         if (strcmp(errorMsg,"Code moved during pass 2")){
  213.           int errLine = atoi(substr(GetLine(),0,5));
  214.           string errorText = substr(GetLine(),39,ReadInfo("line_length")-39);
  215.  
  216.           CurrentBuffer(parentBuffer);
  217.  
  218.           GotoLine(errLine);
  219.  
  220.           if (0<Isfold()){
  221.             FoldShow();
  222.             FoldShow();
  223.             GotoLine(errLine);
  224.           }
  225.  
  226.           ReturnStatus(errorMsg+" ("+errorText+")");
  227.         } else
  228.           retry = 1;                        // skip error line
  229.       }
  230.     }
  231.   }
  232. }
  233.  
  234.  
  235.  
  236. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» TrashMOneMode settings ««
  237. ConstructInfo("trashProgress","","","LSH","",0,0,". ..........");
  238.  
  239. SetInfo(-1,"status_line",ReadInfo("status_line")+" $'trashProgress'");
  240.  
  241. ConstructInfo("trash_mode","","","LBH","",0,1,0);
  242. ConstructInfo("trash_mode_ext","","","GSWH","",0,0,"*asm*s*i*");
  243. ConstructInfo("trash_mode_exe","","","GSWH","",0,0,"AsmModeInit();");
  244.  
  245. AddMode(1,"trash_mode", "trash_mode_ext", "trash_mode_exe"); // Add as major mode
  246.  
  247. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Key Bindings ««
  248. AssignKey("assembleBuffer(0);","'esc'", "trash_mode");
  249. AssignKey("assembleBuffer(1);","shift 'esc'", "trash_mode");
  250.  
  251. AssignKey("nextError();","control c '0x2a'","trash_mode");
  252.